<?php

include_once "class_radcodes.php";


function imobile_hook_footer()
{
  global $page;
  
  $smarty =& SESmarty::getInstance();
  
  if(rc_imobile::is_mobile_display()) {
    
    $smarty->assign('imobile_plugin_menu', rc_imobile::get_supported_plugin_menu());
    
    $templatemode = rc_toolkit::get_setting('imobile_templatemode');
    
    $filename = basename($_SERVER['SCRIPT_NAME'], ".php");
    $pagename = $page;
    
    if ($templatemode == 1) {
      $imobile_page = "imobile_{$filename}";
    }
    elseif ($templatemode == 2) {
      if ($smarty->template_exists("imobile_{$pagename}.tpl")) {
        $imobile_page = "imobile_{$pagename}";
      }
      else if ($smarty->template_exists("imobile_{$filename}.tpl")) {
        $imobile_page = "imobile_{$filename}";
      }
      else {
        $imobile_page = "imobile_{$pagename}";
      }
    }
    else {
      $imobile_page = "imobile_{$pagename}";
    }
    
    $imobile_debug['user_agent'] = $_SERVER['HTTP_USER_AGENT'];
    $imobile_debug['variables'] = array(
      'filename' => $filename,
      'pagename' => $page,
      'imobile_page' => $imobile_page,
    );
    
    $smarty->assign('imobile_debug', $imobile_debug);
    
    
    if ($smarty->template_exists("{$imobile_page}.tpl")) {
      $page = $imobile_page;
    }
    else {
      
	  $page = "imobile_error";
	  $smarty->assign('error_header', 11340052);
	  $smarty->assign('error_message', 11340053);
	  $smarty->assign('error_submit', 11340054);
	  //include "footer.php";
      //exit;
    }
  }

}


function imobile_hook_page_profile()
{
  global $owner;
  
  $cpp = 20;
  $p = 1;
  $type = 'profile';
  $iden = 'user_id';
  $value = $owner->user_info['user_id'];
  $tab = null;
  $col = null;
  $comment = new se_comment($type, $iden, $value, $tab, $col); 
  
  $total_comments = $comment->comment_total();
  $page_vars = make_page($total_comments, $cpp, $p);
  $comments = $comment->comment_list($page_vars[0], $cpp);
  
  $smarty =& SESmarty::getInstance();
  $smarty->assign('comments', $comments);
  
  //print_r($comments);
  
}

function imobile_hook_page_user_friends()
{
  global $user, $total_friends, $sort, $where, $show_details;
  
  $p = 1;
  $friends_per_page = 999999;
  $page_vars = make_page($total_friends, $friends_per_page, $p);
	
  $sort = "se_users.user_displayname";
  
  // GET FRIEND ARRAY
  $friends = $user->user_friend_list($page_vars[0], $friends_per_page, 0, 1, $sort, $where, $show_details);
	  
  
  $smarty =& SESmarty::getInstance();
  $smarty->assign('friends', $friends);
}


function imobile_hook_page_business()
{
  global $owner, $business;
  
  $cpp = 20;
  $p = 1;
  $type = 'business';
  $iden = 'business_id';
  $value = $business->business_info['business_id'];
  $tab = null;
  $col = null;
  $comment = new se_comment($type, $iden, $value, $tab, $col); 
  
  $total_comments = $comment->comment_total();
  $page_vars = make_page($total_comments, $cpp, $p);
  $comments = $comment->comment_list($page_vars[0], $cpp);
  
  $smarty =& SESmarty::getInstance();
  $smarty->assign('comments', $comments);
  
  //print_r($comments);
  
}
